package com.wb.factory;

import com.wb.utils.FileName;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;

import java.io.File;

public class FastFileName extends FileNameFactory{
    /**
     * @param template 模板名称
     * @param basePath 文件夹路径
     * @ moduleName 模块名称  如 jxfp/sys
     * @ packageName 包名  com.wb/ com.jx
     * @param type 区分前后端代码
     * @param className 当前class名称
     * @return
     */
    @Override
    FileName createFileName(String template, String basePath, Configuration personalConfiguration, String className, String type) {
        String packageName=personalConfiguration.getString("package");
        String moduleName=personalConfiguration.getString("moduleName");
        String packagePath = basePath+"src"+ File.separator+"main" + File.separator + "java" + File.separator;
                if (type.equals("backendPath")){
                    if (StringUtils.isNotBlank(packageName)) {
                        packagePath += packageName.replace(".", File.separator) + File.separator + moduleName + File.separator;
                    }
//            if (template.contains("MongoChildrenEntity.java.vm")) {
//                return packagePath + "entity" + File.separator + "inner" + File.separator + currentTableName+ File.separator + splitInnerName(className)+ "InnerEntity.java";
//            }
                    if (template.contains("Entity.java.vm") || template.contains("MongoEntity.java.vm")) {
                        return new FileName(packagePath + "entity" + File.separator + className + "Entity.java");
                    }

                    if (template.contains("Dao.java.vm")) {
                        return new FileName(packagePath + "dao" + File.separator + className + "Dao.java");
                    }

                    if (template.contains("Service.java.vm")) {
                        return new FileName(packagePath + "service" + File.separator + className + "Service.java");
                    }

                    if (template.contains("ServiceImpl.java.vm")) {
                        return new FileName(packagePath + "service" + File.separator + "impl" + File.separator + className + "ServiceImpl.java");
                    }

                    if (template.contains("Controller.java.vm")) {
                        return new FileName(packagePath + "controller" + File.separator + className + "Controller.java");
                    }

                    if (template.contains("Dao.xml.vm")) {
                        return  new FileName(basePath+"src"+File.separator+"main"  + File.separator + "resources" + File.separator + "mapper" + File.separator + moduleName + File.separator + className + "Dao.xml");
            }
//            if (template.contains("menu.sql.vm")) {
//                return className.toLowerCase() + "_menu.sql";
//            }
        }
//        else if (type.equals("frontEndPath")){
//            if (template.contains("index.vue.vm")) {
//                return moduleName + File.separator + className.toLowerCase() + ".vue";
//            }
//            if (template.contains("add-or-update.vue.vm")) {
//                return moduleName + File.separator + className.toLowerCase() + "-add-or-update.vue";
//            }
        return null;
    }
}
